package com.qf.fmall2203.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.fmall2203.product.entity.ProductParams;
import com.qf.fmall2203.product.service.IProductCommentsService;
import com.qf.fmall2203.product.service.IProductParamsService;
import com.qf.fmall2203.product.service.IProductService;
import com.qf.fmall2203.utils.ResultVo;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 商品 商品信息相关表：分类表，商品图片表，商品规格表，商品参数表 前端控制器
 * </p>
 *
 * @author dongjl
 * @since 2023-02-15
 */
@CrossOrigin
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    IProductService productService;

    @Autowired
    IProductParamsService productParamsService;

    @Autowired
    IProductCommentsService productCommentsService;


    /**
     * 商品好评率
     */
    @GetMapping("/detail-commontscount/{id}")
    public ResultVo detailCommontscount(@PathVariable("id") Integer id){

        HashMap<String,Object> data = productCommentsService.detailCommontscount(id);

        return ResultVo.ok(data);

    }

    /**
     * 商品评论信息
     */
    @GetMapping("/detail-commonts/{id}")
    public ResultVo detailCommonts(@PathVariable("id") Integer id,Integer pageNum,Integer limit ){

        HashMap<String,Object> data = productCommentsService.detailCommonts(id,pageNum,limit);

        return ResultVo.ok(data);

    }


    /**
     * 商品参数信息
     * @param id
     * @return
     */
    @GetMapping("/detail-params/{id}")
    public ResultVo detailParams(@PathVariable("id") Integer id){

        final ProductParams data = productParamsService.getOne(new QueryWrapper<ProductParams>().eq("product_id", id));

        return ResultVo.ok(data);

    }


    /**
     * 商品详情信息
     * @param id
     * @return
     */
    @GetMapping("/detail-info/{id}")
    public ResultVo detailInfo(@PathVariable("id") Integer id){

        Map<String,Object> data = productService.detailInfo(id);

        return ResultVo.ok(data);
    }

}
